﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Channels.Ipc;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using System.Security.Permissions;
using PSIEpics;
using epics_server_remoting_class;


namespace epicsServer_remoting_client
{
    class Program
    {
        static void Main(string[] args)
        {
                // 创建一个IPC信道。
            IpcChannel channel = new IpcChannel();
            
            // 注册这个信道。
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel);

            // 注册一个远程对象的客户端代理.
            System.Runtime.Remoting.WellKnownClientTypeEntry remoteType = new System.Runtime.Remoting.WellKnownClientTypeEntry(typeof(EpicsServer_Remoting), "ipc://TestChannel/EpicsServer_Remoting.rem");
            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(remoteType);

            EpicsServer_Remoting myRemoteserver= new EpicsServer_Remoting();
            Record_prop my_rp=new Record_prop ();
             
            string pvName;
            Console.WriteLine("pv neam:");
            pvName = Console.ReadLine();
            my_rp.DESC = "suker";
            my_rp.HIGH = 100;
            my_rp.HIHI  = 150;

            //myRemoteserver.addRecord<double>(pvName, true, my_rp);
            //myRemoteserver.setRecord<double>(pvName, 10);

            myRemoteserver.addRecordArray<short>(pvName, 5, true);
            short[] v = new short[5];
            for (int i = 0; i <= 4; i++)
            {
                v[i] = (short)(i + 5);
            }
            myRemoteserver.setRecordArray<short>(pvName, v, 0, 4);

            Console.WriteLine("server_run");
            short  [] a;
            string value;
            do
            {
                value = Console.ReadLine();
                //double b = myRemoteserver.getRecord<double>(pvName);
                a=myRemoteserver.getRecordArray2<short>(pvName,6);
                //myRemoteserver.getRecordArray(pvName,ref  v);
                for (int i = 0; i <= 4; i++)
                {
                    //v[i] = (short)(i + Convert.ToInt32(value));

                    Console.WriteLine(a[i].ToString());
                }
                //myRemoteserver.setRecordArray<short>(pvName, v, 0, 4);
                //double a = Convert.ToDouble(value);
                //myRemoteserver.setRecord<double>(pvName,a  );
                //Console.WriteLine(b.ToString());
            } while (value != "0");
            Console.ReadLine();

        }
    }
}
